function radix_sort(arr) {
    let ret = Array(arr.length).fill(0),
        cnt = Array(65536).fill(0);
    for (let v of arr) cnt[v % 65536]++;
    for (let i = 1; i < 65536; i++) cnt[i] += cnt[i - 1];
    for (let i = arr.length - 1; i >= 0; i--) {
        ret[--cnt[arr[i] % 65536]] = arr[i];
    }
    cnt.fill(0);
    for (let v of ret) cnt[(v / 65536) | 0]++;
    for (let i = 1; i < 65536; i++) cnt[i] += cnt[i - 1];
    for (let i = arr.length - 1; i >= 0; i--) {
        arr[--cnt[(ret[i] / 65536) | 0]] = ret[i];
    }
    return ret;s
}

let arr = [8, 6, 9, 4, 5, 0, 1, 3, 2, 7];
radix_sort(arr);
console.log(arr);
